package de.g18.gruppe3.gui.view;

import java.awt.*;
import javax.swing.*;

public class UMView extends JFrame {
	
	/**
	 * Hauptansicht des Programms.
	 * Es können neue Benutzer erfasst werden und jene einer Datei bzw. einer Datenbank hinzugefügt werden.
	 * 
	 * Anschliessend können Userlisten aus einer Datei oder Datenbank mit dem AD abgeglichen werden.
	 *
	 * @author <a href="madmakro@gmx.net">Jan Schwart</a>
	 */

	//Membervariablen
	private static final long serialVersionUID = 1L;
	
	private JPanel pUCViewMain = new JPanel();
	private JPanel pUCViewTop = new JPanel();
	private JPanel pUCViewTopUser = new JPanel();
	private JPanel pUCViewTopButton = new JPanel();
	private JPanel pUCViewBottom = new JPanel();
	private JPanel pUCViewBottomLabel = new JPanel();
	private JPanel pUCViewBottomButton = new JPanel();
	
	private JLabel lUCLogin = new JLabel("Loginname: ");
	private JLabel lUCVorName = new JLabel("Vorname: ");
	private JLabel lUCNachName = new JLabel("Nachname: ");
	private JLabel lUCGruppe = new JLabel("Benutzergruppe: ");
	private JLabel lUCPasswort = new JLabel("Passwort: ");
	
	private JTextArea lUCAddDescription = new JTextArea();
	
	private JTextField tfUCLogin = new JTextField();
	private JTextField tfUCVorName = new JTextField();
	private JTextField tfUCNachName = new JTextField();
	private JTextField tfUCGruppe = new JTextField();
	
	private JPasswordField pfUCPasswort = new JPasswordField();
	
	private JButton bUCTopFile = new JButton("Zu Datei hinzufügen");
	private JButton bUCTopFilePath = new JButton("Datei wählen");
	private JButton bUCTopSql = new JButton("Zu Datenbank hinzufügen");
	private JButton bUCTopSqlPath = new JButton("Datenbank wählen");
	
	private JButton bUCBottomFile = new JButton("Aus Datei hinzufügen");
	private JButton bUCBottomSql = new JButton("Aus Datenbank hinzufügen");

	//Konstruktor
	public UMView(String title){
		super(title);
		initializeComponents();

	    setLayout(new BorderLayout());

	    add(pUCViewMain, BorderLayout.CENTER);

	    setDefaultCloseOperation(EXIT_ON_CLOSE);
	    setSize(480, 350);
	    setLocation(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().x-(getWidth()/2),
    			GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().y-(getHeight()/2));
	    setResizable(false);
	    setVisible(true);

	}

	//Initialisierung der GUI-Komponenten
	private void initializeComponents() {

		//ViewTopUser
		pUCViewTopUser.setLayout(new GridLayout(5, 2, 5, 5));
		pUCViewTopUser.add(getlUCLogin());
		pUCViewTopUser.add(gettfUCLogin());
		pUCViewTopUser.add(getlUCVorName());
		pUCViewTopUser.add(gettfUCVorName());
		pUCViewTopUser.add(getlUCNachName());
		pUCViewTopUser.add(gettfUCNachName());
		pUCViewTopUser.add(getlUCGruppe());
		pUCViewTopUser.add(gettfUCGruppe());
		pUCViewTopUser.add(getlUCPasswort());
		pUCViewTopUser.add(getpfUCPasswort());
		
		//ViewTopButton
		pUCViewTopButton.setLayout(new GridLayout(2, 2, 5, 5));
		pUCViewTopButton.add(getbUCTopFilePath());
		pUCViewTopButton.add(getbUCTopFile());
		pUCViewTopButton.add(getbUCTopSqlPath());
		pUCViewTopButton.add(getbUCTopSql());
		
		//ViewTop
		pUCViewTop.setLayout(new BorderLayout());
		pUCViewTop.setBorder(BorderFactory.createTitledBorder("Neue Benutzer anlegen"));
		pUCViewTop.setPreferredSize(new Dimension(200, 210));
		pUCViewTop.add(pUCViewTopUser, BorderLayout.NORTH);
		pUCViewTop.add(pUCViewTopButton, BorderLayout.SOUTH);
		
		//AddDesciption
		lUCAddDescription.setMargin(new Insets(0,5,10,5));
		lUCAddDescription.setLineWrap(true);
		lUCAddDescription.setWrapStyleWord(true);
		lUCAddDescription.setBackground(null);
		lUCAddDescription.setText("VORSICHT!");
		
		//ViewBottomLabel
		pUCViewBottomLabel.setLayout(new GridLayout());
		pUCViewBottomLabel.add(getlUCAddDescription());
		
		//ViewBottomButton
		pUCViewBottomButton.setLayout(new GridLayout(1, 2, 5, 5));
		pUCViewBottomButton.add(getbUCBottomFile());
		pUCViewBottomButton.add(getbUCBottomSql());
		
		//ViewBottom
		pUCViewBottom.setLayout(new BorderLayout());
		pUCViewBottom.setBorder(BorderFactory.createTitledBorder("Benutzerdaten in Active Directory"));
		pUCViewBottom.add(pUCViewBottomLabel, BorderLayout.NORTH);
		pUCViewBottom.add(pUCViewBottomButton, BorderLayout.SOUTH);
		
		//ViewMain
		pUCViewMain.setLayout(new BorderLayout());
		pUCViewMain.setBorder(BorderFactory.createEmptyBorder(8, 12, 4, 12));
		pUCViewMain.add(pUCViewTop, BorderLayout.NORTH);
		pUCViewMain.add(pUCViewBottom, BorderLayout.SOUTH);

	}

	//Getter
	public JLabel getlUCLogin() { return lUCLogin; }
	public JLabel getlUCVorName() { return lUCVorName; }
	public JLabel getlUCNachName() { return lUCNachName; }
	public JLabel getlUCGruppe() { return lUCGruppe; }
	public JLabel getlUCPasswort() { return lUCPasswort; }
	
	public JTextArea getlUCAddDescription() { return lUCAddDescription; };

	public JTextField gettfUCLogin() { return tfUCLogin; }
	public JTextField gettfUCVorName() { return tfUCVorName; }
	public JTextField gettfUCNachName() { return tfUCNachName; }
	public JTextField gettfUCGruppe() { return tfUCGruppe; }
	public JPasswordField getpfUCPasswort() { return pfUCPasswort; }

	public JButton getbUCTopFile() { return bUCTopFile; }
	public JButton getbUCTopFilePath() { return bUCTopFilePath; }
	public JButton getbUCTopSql() { return bUCTopSql; }
	public JButton getbUCTopSqlPath() { return bUCTopSqlPath; }
	public JButton getbUCBottomFile() { return bUCBottomFile; }
	public JButton getbUCBottomSql() { return bUCBottomSql; }
	
}